package com.db.gffxo.epi.trigger;

import java.util.ArrayList;
import java.util.Iterator;

import javax.sql.DataSource;

import org.apache.log4j.Logger;

public abstract class AbstractTrigger {

	
	private DataSource dataSource;
	Logger logger = Logger.getLogger(this.getClass().getName());
	
	protected class KeyInfo {
		String key;
		String value;
		
		protected KeyInfo (String key, String value) {
			this.key=key;
			this.value=value;
		}
	}
	
		
	public void runTask () {
		// Execute the method on the trigger implementation
		StringBuffer allKeys = new StringBuffer();
		ArrayList<KeyInfo> keys;
		try {
			keys = execute();
			
			allKeys.append("|");
			Iterator<KeyInfo> it = keys.iterator();
			while (it.hasNext()) {
				KeyInfo ki = it.next();
				allKeys.append(ki.key);
				allKeys.append("=");
				allKeys.append(ki.value);
				allKeys.append("|");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			
		}
		
		System.out.println(allKeys.toString());
		
	}
	
	
	protected abstract ArrayList execute ();


	//getDataSource();
	public DataSource getDataSource() {
		return dataSource;
	}


	//setDataSource(rs.getDataSource(10));
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
}
